package com.tspp.entrantsAcceptor;

import com.tspp.dao.DaoException;
import com.tspp.dao.DaoFactory;
import com.tspp.dao.EntrantDao;
import com.tspp.dao.GroupaDao;
import com.tspp.dao.dto.Entrant;
import com.tspp.dao.dto.Groupa;
import java.util.List;

/**
 * Class that manipulate etrants
 * @author Maks
 */
public class EntrantsAcceptorBean {

    /**
     * Get all entrants
     * @return list of all entrants
     * @throws DaoException
     */
    public List<Entrant> getEntrants() throws DaoException {
        return DaoFactory.getEntrantDao().findAll();
    }

    /**
     * Add new entrant
     * @param entrant new Entrant
     * @throws DaoException
     */
    public void addEntrant(Entrant entrant) throws DaoException {
        EntrantDao dao = DaoFactory.getEntrantDao();
        dao.insert(entrant);
    }

    /**
     * Update info about entrant with specified id
     * @param id
     * @param entrant
     * @throws DaoException
     */
    public void updateEntrant(int id, Entrant entrant) throws DaoException {
        EntrantDao dao = DaoFactory.getEntrantDao();
        dao.update(id, entrant);
    }

    /**
     * Delete entrant with specified id
     * @param id
     * @throws DaoException
     */
    public void deleteEntrant(int id) throws DaoException {
        EntrantDao dao = DaoFactory.getEntrantDao();
        dao.delete(id);
    }

    /**
     * 
     * @param group
     * @return
     * @throws DaoException
     */
    public String getGroupCode(int group) throws DaoException {
        GroupaDao dao = DaoFactory.getGroupaDao();
        Groupa gr = dao.findByPrimaryKey(group);
        if (gr == null)
            return "no group";
        else return gr.getCode();
    }

    public List<Groupa> getGroups() throws DaoException {
        GroupaDao dao = DaoFactory.getGroupaDao();
        return dao.findAll();
    }

}
